package com.hyh.pay.controller;


import com.alipay.api.AlipayApiException;
import com.hyh.pay.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/api/pay")
@ComponentScan(basePackages = "com.hyh")
public class PayController {

    @Autowired
    private PayService payService;



    @GetMapping("/payFor")
    public String pay(@RequestParam(value = "orderNumber") String  orderNumber) throws AlipayApiException {
        return  payService.pay(orderNumber);
    }


    /*
     * @description: 回调函数
     * @param:
     * @return:
     * @author
     * @date: 2024/3/22 15:39
     */
    @PostMapping("/callback")  // 注意这里必须是POST接口
    public String payNotify(HttpServletRequest request) throws Exception {
       return payService.payNotify(request);
    }

    /*
     * @description: 退款接口
     * @param:
     * @return:
     * @author
     * @date: 2024/3/28 15:51
     */

   @GetMapping("/refund")
    public String refund(@RequestParam(value = "orderNumber") String orderNumber) throws AlipayApiException {
        return payService.refund(orderNumber);
    }
}
